//  @ Project : GagalPanen
//  @ File Name : creatures.cpp
//  @ Date : 3/9/2011
//  @ Author : Denis
//
//

#include "creatures.hpp"

Creatures::Creatures(GameInterface* game) :
        game_(game), drop_boxes_(game), plants_(game), player_(game),
        sprites_(game) {
  return;
}

Creatures::Creatures(GameInterface* game, std::ifstream& is) :
        game_(game), drop_boxes_(game, is), plants_(game, is), player_(game, is),
        sprites_(game, is) {
  return;
}

void Creatures::save(std::ofstream& os) {
  getDropBoxes()->save(os);
  getPlants()->save(os);
  getPlayer()->save(os);
  getSprites()->save(os);
}

Creatures::~Creatures() {}

void Creatures::advanceDay() {
  drop_boxes_.advanceDay();
  plants_.advanceDay();
  player_.advanceDay();
  sprites_.advanceDay();
  return;
}

void Creatures::advanceTime() {
  drop_boxes_.advanceTime();
  plants_.advanceTime();
  player_.advanceTime();
  sprites_.advanceTime();
  return;
}

DropBoxes* Creatures::getDropBoxes() {
  return &drop_boxes_;
}

Plants* Creatures::getPlants() {
  return &plants_;
}

Player* Creatures::getPlayer() {
  return &player_;
}

Sprites* Creatures::getSprites() {
  return &sprites_;
}

bool Creatures::containsUnsteppableCreatureAt(Cell* cell) {
  if (getPlayer()->getCell() == cell && getPlayer()->isSteppable() == false) {
    return true;
  }
  if (getPlants()->containsPlantAt(cell) &&
          getPlants()->getPlantAt(cell)->isSteppable() == false) {
    return true;
  }
  if (getDropBoxes()->containsDropBoxAt(cell) &&
      getDropBoxes()->getDropBoxAt(cell)->isSteppable() == false) {
    return true;
  }
  if (getSprites()->containsSpriteAt(cell) &&
          getSprites()->getOneSpriteAt(cell)->isSteppable() == false) {
    return true;
  }
  return false;
}

